#!/usr/bin/env ruby
# frozen_string_literal: true

require "benchmark/ips"
require "bridgetown"
require "json"

DATA = { "foo" => "bar", "alpha" => { "beta"=>"gamma" }, "lipsum" => %w(lorem ipsum dolor) }.freeze

def local_require
  require "json"
  JSON.pretty_generate(DATA)
end

def global_require
  JSON.pretty_generate(DATA)
end

def graceful_require
  Bridgetown::External.require_with_graceful_fail("json")
  JSON.pretty_generate(DATA)
end

Benchmark.ips do |x|
  x.report("local-require") { local_require }
  x.report("global-require") { global_require }
  x.report("graceful-require") { graceful_require }
  x.compare!
end
